3

I have a view with 4 articles within a colored box. When the screen is wide enough they need to be displayed side by side and have the same height like this:

Article 1 Article 2
Article 3 Article 4

I have tried adding the style so the container - row and columns have following style, but to no result either:

.container-height{
display:table;
}
.row-height{
display:table-row;
}
.col-height{
display:table-cell;
float:none;
} 

https://plnkr.co/edit/vrlHw8tepKZ5nj4SW8EB?p=preview

ketan
19.4k42 gold badges68 silver badges107 bronze badges
asked May 5, 2016 at 6:58
10
  • 4 column in 1 row with same height?? Commented May 5, 2016 at 7:04
  • 2 side by side, my bad in the question, will modify Commented May 5, 2016 at 7:05
  • Why not give your <article> tag a class and set its fixed height via CSS? Commented May 5, 2016 at 7:10
  • try using min-height Commented May 5, 2016 at 7:10
  • 1
    Possible duplicate of How can I make Bootstrap columns all the same height? Commented May 5, 2016 at 7:25

3 Answers 3

1

Well, if you are ok with jquery solution then please have a look at this code.

Check fiddle

$(document).ready(function(e) {
 var heightNew = 0;
 $('.col-md-6 article').each(function(index, element) {
 if($(this).height() > heightNew){
 heightNew = $(this).height();
 }
 $(this).css('height', heightNew+'px');
 });
});

so just add this in tag and use this css.

article{
 text-align:center;
 background-color:lightgray;
 margin:0 25px 50px 25px;
}
h1, p{
 padding:10px;
}

What i did is, i took max-height of article and give that height to other so who ever is the biggest article, all article will be the same height. Hope you will like my idea. Thank you

answered May 5, 2016 at 7:17
Sign up to request clarification or add additional context in comments.

6 Comments

Can't we do it with css only?
@GauravAggarwal m not sure. That's why i added that if you are ok with jquery. But with css, i don't think it will be possible as content will increase in any article will lead to different height..
it is possible with css if he change a bit of html structure...but this also works of he can use jquery
Well m sorry but m not sure its possible with css(and busy in office so i can't give much time) but if you have any better solution then please post. I will learn too :)
this is a working solution i also got, but i'm trying to get a css solution
|
0

getting them along side each other can be achieved by using the bootstrap class col-lg-6 in the case of 2 cols this adds up to 12 and only be active on a large screen (from 1200px and up)

the quickest way to get the equal height for all of the columns (in case of fixed content) is by setting the height, making use of a media query

@media(min-width: 1200){ height: xx; }

answered May 5, 2016 at 7:13

1 Comment

Could be a possibility, but then whenever the contents change a recalculation is required for the good height
0

If you using Bootstrap. This code very helpfull for you

<!DOCTYPE html>
<html>
 <head>
 <link rel="stylesheet" href="style.css">
 <script src="script.js"></script>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
 <link rel="stylesheet" href="http://getbootstrap.com.vn/examples/equal-height-columns/equal-height-columns.css">
 <!-- Optional theme -->
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
 <!-- Latest compiled and minified JavaScript -->
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
 </head>
 <body>
 <div class="container">
 <div class="row row-eq-height">
 <div class="col-md-6">
 <h1>Header 1 </h1>
 <p>Lorem ipsum dolor sdfdfdit amet, duo latine euismod ut. Nullam lobortis nec cu, vel nisl simul at. Ad pro omnis quando suavitate, est ea quod autem perfecto, eros brute nusquam pri ut. At saepe dicant euismod nec.. Lorem ipsum dolor sdfdfdit amet, duo latine euismod ut. Nullam lobortis nec cu, vel nisl simul at. Ad pro omnis quando suavitate, est ea quod autem perfecto, eros brute nusquam pri ut. At saepe dicant euismod nec..</p>
 </div>
 <div class="col-md-6">
 <h1>Header 1 </h1>
 <p>Lorem ipsum dolor sit fdfdfamet, duo latine euismod ut. Nullam lobortis nec cu, vel nisl simul at. Ad pro omnis quando suavitate, est ea quod autem perfecto, eros brute nusquam pri ut. At saepe dicant euismod nec..</p>
 </div>
 <div class="col-md-6">
 <h1>Header 1 </h1>
 <p>Lorem ipsum dolor sidfdft amet, duo latine euismod ut. Nullam lobortis nec cu, vel nisl simul at. Ad pro omnis quando suavitate, est ea quod autem perfecto, eros brute nusquam pri ut. At saepe dicant euismod nec..</p>
 </div>
 <div class="col-md-6">
 <h1>Header 1 </h1>
 <p>Lorem ipsum dolor sit afgfmet, duo latine euismod ut. Nullam lobortis nec cu, vel nisl simul at. Ad pro omnis quando suavitate, est ea quod autem perfecto, eros brute nusquam pri ut. At saepe dicant euismod nec..</p>
 </div>
 </div>
 </div>
 </body>
</html>
<!-- begin snippet: js hide: false -->

answered May 5, 2016 at 7:49

2 Comments

wish that could be that simple, but have you see his demo? he want that way - two row, with two col inside each
But it is possible to put the equal height class on the cols, see bootstrap docs docs

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.